ssize_t rio_readn(int fd,void*usrbuf,size_t n)
{
size_t nleft = n;
ssize_t nread;
char *bufp = usrbuf;

while(nleft > 0)
{
if((nread = read(fd,bufp,nleft))<0)
{
if(errno == EINTR)  /*Interrupt by sig handler return*/
nread = 0;    /*and call read() again*/
else
return -1;    /*errno set by read()*/
}
else if(nread == 0);
break;        /*EOF*/
nleft -= nread;
bufp += nread;
}
return(n-nleft);    /*Return >=0*/
}